草庐IT

java - Mockito 在测试方法之外 stub

全部标签

Java 有 FindBugs。 Ruby 的等价物是什么?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:AutomaticcodequalitytoolforRuby?Java有FindBugs™。Ruby的等价物是什么?

ruby-on-rails - 仅当特定实例变量具有值时,如何 stub 实例方法?

我有一个对象MyObject:classMyObjectdefinitialize(options={})@stat_to_load=options[:stat_to_load]||'test'enddefresults[]endend仅当stat_to_load="times"时,我才想stubresults方法。我怎样才能做到这一点?我试过了:MyObject.any_instance.stubs(:initialize).with({:stat_to_load=>"times"}).stubs(:results).returns(["klala"])但它不起作用。有什么想法吗?

ruby-on-rails - 从帮助器规范中 stub 一个帮助器方法

我正在构建Rails应用程序并使用RSpec制定测试。我为我正在创建的名为current_link_to的方法编写了测试。此方法应该检查当前页面是否对应于我传递给它的路径,并将current类添加到生成的链接中,以防它匹配。这是规范:require"spec_helper"describeApplicationHelperdodescribe"#current_link_to"dolet(:name){"Products"}let(:path){products_path}let(:rendered){current_link_to(name,path)}context"whenthe

ruby - 在多个线程中引用类方法会导致自动加载循环依赖崩溃

代码:threads=[]Thread.abort_on_exception=truebegin#throwexceptionsinthreadssowecanseethemthreadseputs"EXCEPTION:#{e.inspect}"puts"MESSAGE:#{e.message}"end崩溃:.rvm/gems/ruby-2.1.3@req/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:478:inload_missing_constant':自动加载常量MyClass时检测到循环依赖稍加研究后,

ruby-on-rails - 使用多个数据库测试 Rails 应用程序

我有一个Rails应用程序,它在production环境中使用两个数据库,Users和Process。Users模型使用这个自定义的ActiveRecord类:classUserActiveRecord请注意,与特定数据库的连接是根据环境建立的。为了简化事情,在测试环境中,我有一个数据库,其中包含两个生产数据库中的所有表,我的database.yml文件看起来像这样:test:adapter:postgresqldatabase:db_testhost:localhostpool:...timeout:...username:...password:...test_users_db:a

ruby-on-rails - rspec Mongoid 范围适用于开发而不是测试

我有一个适用于Rails中的Mongoid对象的作用域,它在开发时效果很好,但在运行测试时效果不佳。它实际上在测试中根本不起作用。这是一个嵌入式文档。父级:classPersonincludeMongoid::Documentdefself.with_appointmentswhere(:appointments.not=>{'$size'=>0})endembeds_many:appointments,store_as:'Appointments',class_name:'Appointment'end嵌入的child:classAppointmentincludeMongoid::

ruby - 检查是否调用了类方法

我有以下模块和类:moduleMyModuledefself.includedbasebase.extend(ClassMethods)endmoduleClassMethodsattr_reader:config#thismethodMUSTbecalledbyeveryclasswhichincludesMyModuledefconfigure&block@config={}block.call(@config)ifblockendendendclassAincludeMyModuleconfiguredo|config|#dosthwiththeconfigendendclass

ruby-on-rails - 更改回形针附件上集成测试的路径

Paperclip的文档提到,您可以通过将以下代码放在test.rb环境文件中来更改测试的上传路径:Paperclip::Attachment.default_options[:path]="#{Rails.root}/spec/test_files/:class/:id_partition/:style.:extension"我遇到的问题是附件在模型中设置了路径,不会被覆盖:has_attached_file:photo,path:':attachment/:id/:style.:extension'当我运行测试时,文件会上传到/photo/文件夹而不是/spec/test_file

ruby-on-rails - RailsTutorial - 第 8.4.3 章 - 在集成测试中添加用户后未清除测试数据库

我被这个难住了。到目前为止教程中的一切都进行得很顺利,但是当我将这段代码添加到我的/spec/requests/users_spec.rb文件中时,事情开始变得糟糕:describe"success"doit"shouldmakeanewuser"dolambdadovisitsignup_pathfill_in"Name",:with=>"ExampleUser"fill_in"Email",:with=>"ryan@example.com"fill_in"Password",:with=>"foobar"fill_in"Confirmation",:with=>"foobar"cl

ruby - 如何测试在运行之间提供功能的 Ruby 脚本?

单元测试的好方法是测试脚本在执行之间保持正确数据的能力——在使用Ctrl-C终止脚本然后重新运行之后?是否有针对执行类似操作的现有模块或脚本的任何测试可以针对最佳实践进行审查? 最佳答案 像http://avdi.org/devblog/2010/07/19/greenletters-painless-automation-and-testing-for-command-line-applications/一样使用库或者期望、运行、终止并重新运行您的程序,并检查它是否运行正确。好的做法是将程序设计为独立的模块,每个模块都经过良好测试